/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package server;

import HelloApp.*;
import org.omg.CosNaming.*;
import org.omg.CosNaming.NamingContextPackage.*;
import org.omg.CORBA.*;
import org.omg.PortableServer.*;
import org.omg.PortableServer.POA;
import java.util.Properties;

/**
 *
 * @author patrick
 */
public class HelloServer {

    public static void main(String args[]) {
        try {
            
            //init the ORB
            ORB orb = ORB.init(args, null);
            
            //Adapter
            POA rootpoa = POAHelper.narrow(orb.resolve_initial_references("RootPOA"));
            rootpoa.the_POAManager().activate();
            HelloServant helloServant = new HelloServant();
            helloServant.setORB(orb);
            org.omg.CORBA.Object ref = rootpoa.servant_to_reference(helloServant);
            Hello href = HelloHelper.narrow(ref);
            System.out.println("Test");
            org.omg.CORBA.Object objRef = orb.resolve_initial_references("NameService");
            NamingContextExt ncRef = NamingContextExtHelper.narrow(objRef);
            NameComponent cosName[] = ncRef.to_name("HelloObject");
            ncRef.rebind(cosName, href);
            System.out.println("HelloServer ready and waiting ...");
            orb.run();
        } catch (Exception e) {
            System.err.println("ERROR: " + e);
            e.printStackTrace(System.out);
        }
        System.out.println("HelloServer Exiting ...");

    }
}